<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>班级弹框</title>
		<script src="../../../node_modules/layui/dist/layui.js"></script>
		<script src="../../../node_modules/mockjs/dist/mock.js"></script>
		<link rel="stylesheet" type="text/css" href="../../../node_modules/layui/dist/css/layui.css" />
		<link rel="stylesheet/less" type="text/css" href="../../../src/css/style.less" />
		<script src="../../../src/css/less.min.js"></script>
		<script src="../../baseUrl.js"></script>
	</head>
	<body>
		<form class="layui-form layui-form-pane tan" action="" lay-filter="example">
			<input type="hidden" name="id">

			<div class="layui-form-item">
				<label class="layui-form-label">班级名称</label>
				<div class="layui-input-block">
					<input type="text" name="className" lay-verify="bitian" autocomplete="off" placeholder="班级名称"
						class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">班级类型</label>
				<div class="layui-input-block">
					<input type="text" name="classType" lay-verify="bitian" autocomplete="off" placeholder="班级类型"
						class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">班主任</label>
				<div class="layui-input-block">
					<input type="text" name="classTeacher" lay-verify="bitian" autocomplete="off" placeholder="班主任"
						class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">开始时间</label>
				<div class="layui-input-block">
					<input type="text" name="startDate" id="startDate" lay-verify="bitian" autocomplete="off"
						class="layui-input" placeholder="开始时间">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">毕业时间</label>
				<div class="layui-input-block">
					<input type="text" name="endDate" id="endDate" lay-verify="bitian" autocomplete="off"
						class="layui-input" placeholder="毕业时间">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<!-- <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">赋值</button>
					<button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval">取值</button> -->
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
				</div>
			</div>
		</form>

		<script type="text/javascript">
			const { form, layer, layedit, laydate } = layui;

			layui.use(function() {
				//获取当前弹框的数据
				const { classRowData } = parent;
				if (classRowData) {
					//编辑需要回显数据
					form.val('example', classRowData);
				}
				//日期
				laydate.render({
					elem: '#startDate'
				});
				laydate.render({
					elem: '#endDate'
				});
				//自定义验证规则
				form.verify({
					bitian: function(value) {
						if (!value.length) return '必填项'
					}
				});

				//监听提交
				form.on('submit(demo1)', function(data) {
					let xml = new XMLHttpRequest();
					xml.open('POST', `${baseUrl}/api/class/set/`);
					xml.setRequestHeader('Content-type', 'application/json');
					xml.send(JSON.stringify(data.field));
					xml.onreadystatechange = function() {
						if (xml.readyState === 4) {
							if (xml.status === 200) {
								const result = JSON.parse(xml.responseText);
								layer.msg(result.msg);
								//当你在iframe页面关闭自身时
								//先得到当前iframe层的索引
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index); //再执行关闭 
								//刷新列表
								parent.reloadTable()
							}
						}
					}
					return false;
				});
			});
		</script>

	</body>
</html>
